package com.ruoyi.project.system.house.type.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.house.type.domain.HouseType;
import com.ruoyi.project.system.house.type.service.IHouseTypeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 房源类型Controller
 * 
 * @author f_baisi
 * @date 2020-08-27
 */
@Controller
@RequestMapping("/system/house/type")
public class HouseTypeController extends BaseController
{
    private String prefix = "system/house/type";

    @Autowired
    private IHouseTypeService houseTypeService;

    @RequiresPermissions("system/house:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询房源类型列表
     */
    @RequiresPermissions("system/house:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HouseType houseType)
    {
        startPage();
        List<HouseType> list = houseTypeService.selectHouseTypeList(houseType);
        return getDataTable(list);
    }

    /**
     * 导出房源类型列表
     */
    @RequiresPermissions("system/house:type:export")
    @Log(title = "房源类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HouseType houseType)
    {
        List<HouseType> list = houseTypeService.selectHouseTypeList(houseType);
        ExcelUtil<HouseType> util = new ExcelUtil<HouseType>(HouseType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 新增房源类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存房源类型
     */
    @RequiresPermissions("system/house:type:add")
    @Log(title = "房源类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HouseType houseType)
    {
        return toAjax(houseTypeService.insertHouseType(houseType));
    }

    /**
     * 修改房源类型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        HouseType houseType = houseTypeService.selectHouseTypeById(id);
        mmap.put("houseType", houseType);
        return prefix + "/edit";
    }

    /**
     * 修改保存房源类型
     */
    @RequiresPermissions("system/house:type:edit")
    @Log(title = "房源类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HouseType houseType)
    {
        return toAjax(houseTypeService.updateHouseType(houseType));
    }

    /**
     * 删除房源类型
     */
    @RequiresPermissions("system/house:type:remove")
    @Log(title = "房源类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(houseTypeService.deleteHouseTypeByIds(ids));
    }
}
